/*
 * @Author: 江舟 jijiangzhou@recycloud.cn
 * @Date: 2024-08-08 16:03:28
 * @LastEditors: 江舟 jijiangzhou@recycloud.cn
 * @LastEditTime: 2024-08-09 10:53:04
 * @FilePath: \vite-react-web\src\pages\other\message\Index.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { pageInboxs } from 'apis/message';
import { ProColumns, ProTable } from '@ant-design/pro-components';
import { Space, Tag } from 'antd';
import { useNavigate } from 'react-router-dom-v5-compat';

const MessageIndex = () => {
    const navigate = useNavigate();
    const columns: ProColumns<API.PAY_ABLE_TYPE>[] = [
        {
            title: '站内信标题',
            dataIndex: 'title',
        },

        {
            title: '已读标记',
            dataIndex: 'readTag',
            hideInSearch: true,
            render: (text: any, record: API.PAY_ABLE_TYPE, index: number) => {
                return record.readTag === 2 ? <Tag color='green'>已读</Tag> : <Tag color='red'>未读</Tag>;
            },
        },
        {
            title: '操作',
            key: 'option',
            valueType: 'option',
            render: (text: any, record: API.PAY_ABLE_TYPE, index: number) => {
                return (
                    <Space>
                        <a onClick={() => handleDetail(record)}>详情</a>
                    </Space>
                );
            },
        },
    ];

    const handleDetail = (record: API.PAY_ABLE_TYPE) => {
        navigate(`/other/message/${record.id}`);
    };
    return (
        <>
            <ProTable<API.PAY_ABLE_TYPE>
                columns={columns}
                request={(params, sorter, filter) => {
                    let totalPages = 0;
                    return new Promise(async (resolve, reject) => {
                        try {
                            const res = await pageInboxs({
                                ...params,
                                pageNumber: params.current,
                                pageSize: params.pageSize,
                                current: void 0,
                            });
                            totalPages = res?.totalRow || 0;
                            resolve({
                                data: res?.recordDatas || [],
                                success: true,
                                total: totalPages,
                            });
                        } catch (error) {
                            resolve({
                                data: [],
                                success: true,
                                total: 0,
                            });
                        }
                    });
                }}
                rowKey='id'
                pagination={{
                    showQuickJumper: true,
                }}
                search={{
                    layout: 'vertical',
                    defaultCollapsed: false,
                }}
                dateFormatter='string'
                scroll={{
                    y: '66vh',
                }}
            />
        </>
    );
};

export default MessageIndex;
